package com.xzh.springCloud.controller;

import com.xzh.springCloud.entity.Result;
import com.xzh.springCloud.service.AccountService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @Author: zhiHong
 * @CreateTime: 2023-09-01 9:19
 * @Description:
 */
@RestController
public class AccountController {
    @Resource
    private AccountService accountService;


    @PostMapping("/account/reduce")
    public Result<Object> reduce(@RequestParam("userId") Long userId, @RequestParam("money") Integer money) {
        // openfeign 接口调用默认超时时间为 1s
        // 这里我们来进行异常模拟
        //try {
        //    TimeUnit.SECONDS.sleep(12);
        //} catch (InterruptedException e) {
        //    throw new RuntimeException(e);
        //}
        accountService.reduce(userId, money);
        return Result.success("账户余额扣除成功", null);
    }
}
